package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import model.Cliente;

public class RelatorioDao {

    Statement stm;

    Conexao dao = new Conexao();

    Connection con = dao.getConexao();
    
    ResultSet rs;

	public List<Cliente> getLista(Cliente cliente) {
	
		StringBuffer sql = new StringBuffer();
		
		sql.append(" select * from cliente ");
		
		if(!cliente.getCpf().equals("")){
			sql.append("and campocpf = " + cliente.getCpf());
		}
		sql.append("order by nome");
		
		List<Cliente> relatorios = new ArrayList<Cliente>();
		
		try {
			
			stm = con.createStatement();
			String sqlFormatado = sql.toString();
			ResultSet rs = stm.executeQuery(sqlFormatado);
			
			while (rs.next()){
				
				cliente.setCpf(rs.getString("cpf"));
				cliente.setNome(rs.getString("nome"));
				cliente.setCnpj(rs.getString("cnpj"));
				cliente.setRazaoSocial(rs.getString("razaosocial"));
				
				relatorios.add(cliente);
				
			}
			
			return relatorios;
			
		} catch (SQLException e) {
			
			e.getSQLState();
		}
		return relatorios;
		
	}
	
}
